{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "18a3b3c4-647b-41fb-92ad-6487a8fb515f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import tushare as ts"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41ec5220-7ebd-4b17-a782-048fc7280a4b",
   "metadata": {},
   "source": [
    "## 获得300个成分股近3年的日行情数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2dceca36-e7b9-442f-b6fd-08e52b6ff289",
   "metadata": {},
   "outputs": [],
   "source": [
    "ts.set_token('35f337e592e9520154d2a0827c491f75ccc87b723d2bec02cea6b78b')\n",
    "pro = ts.pro_api()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "76b2fe0f-7022-427f-a216-6895fbc569a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>成份券代码Constituent Code</th>\n",
       "      <th>成份券名称Constituent Name</th>\n",
       "      <th>交易所Exchange</th>\n",
       "      <th>权重(%)weight</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>600519</td>\n",
       "      <td>贵州茅台</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>4.767</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>300750</td>\n",
       "      <td>宁德时代</td>\n",
       "      <td>深圳证券交易所</td>\n",
       "      <td>3.430</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>601318</td>\n",
       "      <td>中国平安</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>2.851</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>600036</td>\n",
       "      <td>招商银行</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>2.238</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>300059</td>\n",
       "      <td>东方财富</td>\n",
       "      <td>深圳证券交易所</td>\n",
       "      <td>1.713</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   成份券代码Constituent Code 成份券名称Constituent Name 交易所Exchange  权重(%)weight\n",
       "0                 600519                  贵州茅台     上海证券交易所        4.767\n",
       "1                 300750                  宁德时代     深圳证券交易所        3.430\n",
       "2                 601318                  中国平安     上海证券交易所        2.851\n",
       "3                 600036                  招商银行     上海证券交易所        2.238\n",
       "4                 300059                  东方财富     深圳证券交易所        1.713"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_300_w=pd.read_excel(\"000300closeweight.xlsx\")\n",
    "df_300_w=df_300_w[['成份券代码Constituent Code','成份券名称Constituent Name','交易所Exchange','权重(%)weight']]\n",
    "df_300_w.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "81a87b5a-d2af-4d03-93a8-2c18280fec07",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>成份券代码Constituent Code</th>\n",
       "      <th>成份券名称Constituent Name</th>\n",
       "      <th>交易所Exchange</th>\n",
       "      <th>权重(%)weight</th>\n",
       "      <th>地区</th>\n",
       "      <th>ts_code</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>600519</td>\n",
       "      <td>贵州茅台</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>4.767</td>\n",
       "      <td>SH</td>\n",
       "      <td>600519.SH</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>300750</td>\n",
       "      <td>宁德时代</td>\n",
       "      <td>深圳证券交易所</td>\n",
       "      <td>3.430</td>\n",
       "      <td>SZ</td>\n",
       "      <td>300750.SZ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>601318</td>\n",
       "      <td>中国平安</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>2.851</td>\n",
       "      <td>SH</td>\n",
       "      <td>601318.SH</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>600036</td>\n",
       "      <td>招商银行</td>\n",
       "      <td>上海证券交易所</td>\n",
       "      <td>2.238</td>\n",
       "      <td>SH</td>\n",
       "      <td>600036.SH</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>300059</td>\n",
       "      <td>东方财富</td>\n",
       "      <td>深圳证券交易所</td>\n",
       "      <td>1.713</td>\n",
       "      <td>SZ</td>\n",
       "      <td>300059.SZ</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   成份券代码Constituent Code 成份券名称Constituent Name 交易所Exchange  权重(%)weight  地区  \\\n",
       "0                 600519                  贵州茅台     上海证券交易所        4.767  SH   \n",
       "1                 300750                  宁德时代     深圳证券交易所        3.430  SZ   \n",
       "2                 601318                  中国平安     上海证券交易所        2.851  SH   \n",
       "3                 600036                  招商银行     上海证券交易所        2.238  SH   \n",
       "4                 300059                  东方财富     深圳证券交易所        1.713  SZ   \n",
       "\n",
       "     ts_code  \n",
       "0  600519.SH  \n",
       "1  300750.SZ  \n",
       "2  601318.SH  \n",
       "3  600036.SH  \n",
       "4  300059.SZ  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_300_w[\"地区\"]=df_300_w[\"交易所Exchange\"].map({\n",
    "    \"上海证券交易所\":'SH',\n",
    "    \"深圳证券交易所\":'SZ'\n",
    "})\n",
    "df_300_w[\"ts_code\"]=df_300_w.apply(lambda x:str(x[\"成份券代码Constituent Code\"])+\".\"+x[\"地区\"],axis=1)\n",
    "df_300_w.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "115de2ef-e694-4685-b116-54ddd1de6853",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n",
      "C:\\Users\\Administrator\\AppData\\Local\\Temp\\ipykernel_95736\\3734932550.py:6: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.\n",
      "  df_all=pd.concat([df_all, df_i]).reset_index(drop=True)\n"
     ]
    }
   ],
   "source": [
    "ts_cod=df_300_w[\"ts_code\"].tolist()\n",
    "cols=['ts_code','trade_date','open','high','low','close','pre_close','change','pct_chg','vol','amount']\n",
    "df_all=pd.DataFrame(columns=cols)\n",
    "for cd in ts_cod:\n",
    "    df_i = pro.daily(ts_code=cd, start_date='20211210', end_date='20241211')\n",
    "    df_all=pd.concat([df_all, df_i]).reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d1ca1cec-2265-4eb5-9b52-8657a0a1ff0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_all.to_excel(\"df_all.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "dd920659-0c86-4bb0-af09-07d6d682547d",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_300_w.to_excel(\"df_300_w.xlsx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6afc085-93c6-48b8-a1de-a8d8242bd3c1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c24f6c25-ec72-42e2-9856-e1f5ec20001a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# df_300=pd.read_excel(\"沪深300指数近3年.xlsx\")\n",
    "# df_300.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ddae6f3-f35f-4282-8297-227cf11da8bf",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "31fe9fcf-3c3a-494f-bf80-899c479cf5ec",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ce65425-f95e-4f86-af83-bff4c1e55a04",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f83a790-cab8-4dc5-afd5-349b9427b821",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77d39c87-2941-421c-b6c7-18e189c433f8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
